<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
	<title>Járműveim</title>
	<link rel="stylesheet" type="text/css" media="screen" href="/css/base.css" />
</head>
<body>
	<div class="post">
		<div class="entry">
			<div>
			<h2>Személyes</h2>
			<table class="infoBox">
			    <thead><tr>
				  <th>Név</th>
				  <th>Felhasználónév</th>
				  <th>Szerep</th>
				  <th>E-mail</th>
				  <th>Járművek száma</th>
				</tr></thead>
				<tr>
			      <td><c:out value="${appUser.lastName}" default="[Nincs megadva]"/> <c:out value="${appUser.firstName}"/></td>
			      <td><c:out value="${appUser.userName}"/></td>
			      <td><c:out value="${appUser.roleName}"/></td>
			      <td><c:out value="${appUser.user}"/></td>
			      <td>${fn:length(appUser.vehicles)}</td>
			    </tr>
			</table>
			</div>
			<div style="clear: both;">&nbsp;</div>
			<div><h2>Járművek (${fn:length(appUser.vehicles)})</h2></div>
			<c:choose>
				<c:when test="${!empty appUser.vehicles}">
					<table class="listBox">
					    <thead><tr>
						  <th>Márka</th>
						  <th>Típus</th>
						  <th>Szín</th>
						  <th>Alvázszám</th>
						  <th>Rendszám</th>
						  <th>Létrehozva</th>
						  <th>Bejegyzések</th>
						</tr></thead>
					<c:forEach var="entry" items="${appUser.vehicles}" varStatus="status">
						<tbody>
						<c:choose>
			     			<c:when test='${(status.index)%2 eq 0}'><tr class="odd"></c:when>
			     			<c:otherwise><tr class="even"></c:otherwise>
			     		</c:choose>
					      <td><c:out value="${entry.brand}"/></td>
					      <td><c:out value="${entry.type}"/></td>
					      <td><c:out value='${entry.color}'/></td>				      			      
					      <td><c:out value="${entry.vin}"/></td>
					      <td><c:out value="${entry.regNumber}"/></td>
					      <td><fmt:formatDate pattern="yyyy.MM.dd HH:mm" value="${entry.timeCreated}" /></td>
					      <td>${fn:length(entry.issues)}</td>
					    </tr>
					    </tbody>
					</c:forEach>
					</table>
				</c:when>
				<c:otherwise>
					Nincsenek bejegyzések.
				</c:otherwise>
			</c:choose>
			
			<div style="clear: both;">&nbsp;</div>
			<c:forEach var="vehicle" items="${appUser.vehicles}" varStatus="status">
			<div>
			<h2>Bejegyzések (${fn:length(vehicle.issues)}) (<c:out value="${vehicle.regNumber}"/>)</h2>
				<c:choose>
					<c:when test="${!empty vehicle.issues}">
						<table id="issues" class="listBox">
						    <thead><tr>
							  <th>Mikor?</th>
							  <th>Mi?</th>
							  <th>Kilométer</th>
							  <th>Leírás</th>
							  <th>Létrehozva</th>
							</tr></thead>
							<tbody>
						<c:forEach var="entry" items="${vehicle.issues}" varStatus="status">			
							<c:choose>
				     			<c:when test='${(status.index)%2 eq 0}'><tr class="odd"></c:when>
				     			<c:otherwise><tr class="even"></c:otherwise>
				     		</c:choose>
						      <td><fmt:formatDate pattern="yyyy.MM.dd" value="${entry.issueDate}" /></td>
						      <td><c:out value="${entry.type}"/></td>
						      <th><c:out value="${entry.kilometer}"/></th>
						      <td><c:out value="${entry.description.value}"/></td>
						      <td><fmt:formatDate pattern="yyyy.MM.dd" value="${entry.timeCreated}" /></td>
						    </tr>
						</c:forEach>
						</tbody>
						</table>
					</c:when>
					<c:otherwise>
						Nincsenek bejegyzések.
					</c:otherwise>
				</c:choose>	
			</div>
			</c:forEach>
			
			<div style="clear: both;">&nbsp;</div>
			<a href="/home.jsp">Home</a>
		</div>
	</div>
</body>
</html>